//
//  TextViewUtil.m
//  YiJuZhangShou
//
//  Created by URANUS on 16/3/21.
//  Copyright © 2016年 Uranus. All rights reserved.
//

#import "TextViewUtil.h"
#import "Masonry.h"
#import "DisclosureIndicatorView.h"
#import "UILabel+XExtension.h"


@implementation TextViewUtil

#pragma mark TextView
+(UITextView *)loadTextViewWithTitleLabelWithBackView:(UIView *)backView
                           withTitle:(NSString *)title
                      withTitleColor:(UIColor *)titleColor
                        andTitleFont:(UIFont *)titleFont{
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = title;
    titleLabel.textColor = titleColor;
    titleLabel.font = titleFont;
    titleLabel.tag = TitleTag;
    UITextView *contentTextView = [[UITextView alloc] init];
    contentTextView.textColor = titleColor;
    contentTextView.font = titleFont;
    contentTextView.editable = NO;
    contentTextView.tag = TextViewTag;
    [backView addSubview:titleLabel];
    [backView addSubview:contentTextView];
    
    CGRect labelRect = [titleLabel calculateBounds];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backView);
        make.width.mas_greaterThanOrEqualTo(labelRect.size.width);
        make.top.equalTo(backView).offset(10).priorityLow();
        make.bottom.lessThanOrEqualTo(backView).offset(-5);
    }];
    [contentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(5);
        make.centerY.equalTo(backView);
        make.height.equalTo(backView).multipliedBy(0.9);
        make.right.equalTo(backView).offset(-5);
    }];
    
    return contentTextView;
}

+ (UITextView *)loadIndicatorTextViewWithTitleLabelWithBackView:(UIView *)backView withTitle:(NSString *)title withTitleColor:(UIColor *)titleColor withTitleFont:(UIFont *)titleFont andIndicatorDirection:(DisclosureIndicatorViewDir)dir{
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = title;
    titleLabel.textColor = titleColor;
    titleLabel.font = titleFont;
    titleLabel.tag = TitleTag;
    
    UITextView *contentTextView = [[UITextView alloc] init];
    contentTextView.textColor = titleColor;
    contentTextView.font = titleFont;
    contentTextView.editable = NO;
    contentTextView.tag = TextViewTag;
    
    LabelDisclosureIndicatorView *disclosureIndicatorView = [[LabelDisclosureIndicatorView alloc] init];
    disclosureIndicatorView.dir = dir;
    disclosureIndicatorView.tag = IndicatorViewTag;
    
    [backView addSubview:titleLabel];
    [backView addSubview:contentTextView];
    [backView addSubview:disclosureIndicatorView];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backView).offset(10).priorityLow();
        make.left.equalTo(backView);
        make.width.lessThanOrEqualTo(backView).multipliedBy(0.3);
        make.bottom.lessThanOrEqualTo(backView).offset(-5);
    }];
    [contentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(5);
        make.centerY.equalTo(backView);
        make.height.equalTo(backView).multipliedBy(0.9);
    }];
    [disclosureIndicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(contentTextView.mas_right);
        make.centerY.height.equalTo(contentTextView);
        make.right.equalTo(backView).offset(-5);
        make.width.equalTo(disclosureIndicatorView.mas_height);
    }];
    
    return contentTextView;
}

@end
